<?php
namespace App\Http\Controllers\Api;

use App\Contracts\EventPusher;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Bouncer;
use App\Http\Resources\User as UserResource;
use App\Http\Resources\UserCollection;
use App\Models\Enum\UserEnum;




class User extends Controller
{

    protected $log;


    public function userInfo(Request $req, EventPusher $pusher)
    {
       /* $post = \App\Post::where('id', 1)->first();

        if ( Gate::allows('update2', $post) ) {
            return 'ok';
        } else {
            return '没有权限';
        }*/



       return $pusher->aaa('wubuze');
       return 1;


        return Auth::guard('api')->user();
        return $user =  $req->user('api');


        if ($user->status != UserEnum::NORMAL) {  //使用枚举
            return 'error';
        }

         $data =  new UserResource($req->user());//使用资源

        return $this->success($data);
//        return $this->failed('操作失败');
//        return $this->notFond('操作失败');

    }

    public function list(Request $req) {


        $users = \App\User::paginate(3);
        return UserResource::collection($users);
        //资源集合
        return new UserCollection(\App\User::all());

        $user = $req->user();
        #分配权限给角色
        Bouncer::allow('admin2')->to(['ban-user2','test']);
        #分配角色给用户
        $res = Bouncer::assign(['admin', 'user'])->to($req->user());
//        $res = $req->user()->assign('admin2');

        #用户的所以角色
        $roles = $user->getRoles();
        #用户的权限
//        return $ab = $user->getAbilities();
        Bouncer::allow($user)->to('edit', \App\Post::class);

        return 1;
        if (!$res) {
            return '操作失败';
        }

        \Log::info(($res));

        return 'ok';
    }
}